//= require jquery
//= require rails-ujs
// require activestorage
// require turbolinks
//= require ckeditor/init
//= require_tree ./plugin
//= require cascade/cascade.js
//= require uikit/js/uikit.min.js
//= require uikit/js/core/nav.min.js
//= require uikit/js/components/notify.min.js
//= require uikit/js/components/sticky.min.js
//= require uikit/js/components/form-select.min.js
//= require uikit/js/components/datepicker.min.js
//= require uikit/js/components/lightbox.min.js
//= require uikit/js/components/tooltip.min.js
//= require uikit/js/components/grid-parallax.js
//= require select2/dist/js/select2.min.js
//= require count_up/dist/countUp.min.js
//= require jedate/dist/jedate.min.js
//= require moment/min/moment.min.js
//= require zTree/js/jquery.ztree.core.min.js
//= require_self


$.ajaxSetup({
    headers: {
        'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
    }
});

function toggleInputOther(el, value, c_el){
    var hash = {};
    hash[value] = c_el;
    toggleRadioInput(el, hash);
}

function toggleRadioInput(el, hash){
    for(at in hash){
        $(hash[at]).hide();
    }
    var c_el = $(el+':checked').val();
    if(c_el){
        $(hash[c_el]).show();
    }
}

$(function () {

    $(".select2").select2({
        width: "200px",
        minimumResultsForSearch: -1
    });

    $('.datetime-container').each(function (index) {
        jeDate("#datetime-picker" + String(index + 1), {
            format: "YYYY-MM-DD hh:mm",
            isTime: true,
            minDate: "2014-09-19 00:00:00"
        });
    })

    $('.datetime-container').each(function () {
        if (this.value.length == 0) return;
        var date = moment(this.value, 'YYYY-MM-DD HH:mm').format('YYYY-MM-DD HH:mm');
        $(this).val(date);
    });

    $('.date-container').each(function (index) {
        jeDate("#date-picker" + String(index + 1), {
            format: "YYYY-MM-DD",
            isTime: false,
            minDate: "2014-09-19"
        });
    })

    $('.date-container').each(function () {
        if (this.value.length == 0) return;
        var date = moment(this.value, 'YYYY-MM-DD').format('YYYY-MM-DD');
        $(this).val(date);
    });

})
